package iammry.com.activity;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.Map;

import iammry.com.R;
import iammry.com.base.BaseActivity;


/**
 * 2016-10-25
 *
 * @author kim
 *         TODO 登录类
 */
public class LoginActivtiy extends BaseActivity implements OnClickListener {

    @ViewInject(R.id.iv_weixin)
    ImageView iv_weixin;

    @ViewInject(R.id.ll_root)
    LinearLayout ll_root;

    @ViewInject(R.id.iv_qq)
    ImageView iv_qq;

    UMShareAPI mShareAPI;

    @SuppressWarnings("unused")

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mShareAPI = UMShareAPI.get(LoginActivtiy.this);

    }

    @Override
    protected void initView() {

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // mShareAPI = UMShareAPI.get(this);

        setLayout(this, R.layout.loginactivity_layout);
        //设置字体样式
       // FontManger.changeFonts(ll_root, LoginActivtiy.this);


    }

    @Override
    protected void initData() {

        iv_weixin.setOnClickListener(this);
        iv_qq.setOnClickListener(this);

    }

    @Override
    protected void initEvent() {


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.iv_weixin:

                mShareAPI.doOauthVerify(LoginActivtiy.this, SHARE_MEDIA.WEIXIN, umAuthListener);

                break;

            case R.id.iv_qq:

                mShareAPI.doOauthVerify(LoginActivtiy.this, SHARE_MEDIA.QQ, umAuthListener);

                break;

            default:
                break;
        }

    }


    private UMAuthListener umAuthListener = new UMAuthListener() {
        @Override
        public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {

            Toast.makeText(getApplicationContext(), "Authorize succeed" + data.toString(), Toast.LENGTH_SHORT).show();

            BluetoothAdapter mBlueAdapter = BluetoothAdapter.getDefaultAdapter();

            //判断是否打开蓝牙
            if (!mBlueAdapter.isEnabled()) {
                startActivity(OpenBlueActivity.class);
            } else {
                startActivity(PersonInfoActivity.class);

            }
            finish();


        }

        @Override
        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
            Toast.makeText(getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            Toast.makeText(getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

    }


}
